/**
 * 复制type文件
 * @author dong.c
 */
import fs from 'fs-extra';
import { dirname,resolve,basename } from 'path';
import { fileURLToPath } from 'url';
import { typeFiles } from '../packages/t-types/type.config.js'
import chalk from 'chalk'
import { rimraf } from 'rimraf'


const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const pkgPath = '..//packages/t-types/dist'

function pkg(files){

  let content = '';

  files.forEach(file => {
    content = fs.readFileSync(file, 'utf-8');
    let targetFile = resolve(__dirname, pkgPath, basename(file));
    fs.ensureFileSync(targetFile); // 确保文件存在，如果不存在则创建
    fs.writeFileSync(targetFile, content);
  });


}

rimraf.sync(resolve(__dirname, '../packages/teld-pkgs/dist'))

console.log(`$ 复制定义文件到teld-types `+chalk.green(`开始`))
pkg(typeFiles)
console.log(`$ 复制 `+chalk.green(`完成`))


